package com.waghost.bridalgown.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.waghost.bridalgown.dao.CategoryDao;
import com.waghost.bridalgown.dao.UserBgLikeDao;
import com.waghost.bridalgown.entity.Category;
import com.waghost.bridalgown.entity.Result;
import com.waghost.bridalgown.entity.UserBgLike;
import com.waghost.bridalgown.service.CategoryService;
import com.waghost.bridalgown.service.UserBgLikeService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;

@AllArgsConstructor
@Service
public class IUserBgLikeService implements UserBgLikeService {

    private UserBgLikeDao userBgLikeDao;


    @Override
    public Result list() {
        return Result.success(userBgLikeDao.listMapper());
    }

    @Override
    public Result getId(Integer id) {
        return Result.success(userBgLikeDao.userLikes(id));
    }

    @Override
    public Result add(@RequestBody UserBgLike bgLike) {
        UserBgLike userBgLike = userBgLikeDao.selectOne(new QueryWrapper<UserBgLike>().eq("user_id", bgLike.getUserId()).eq("bridal_gown_id", bgLike.getBridalGownId()));
        if (null != userBgLike){
            return Result.error("您已经收藏过该商品");
        }
        return Result.toAjax(userBgLikeDao.insert(bgLike), "添加成功", "添加错误");
    }

    @Override
    public Result update(UserBgLike bgLike) {
        return Result.toAjax(userBgLikeDao.updateById(bgLike), "修改成功", "修改错误");
    }

    @Override
    public Result delete(Integer id) {
        return Result.toAjax(userBgLikeDao.deleteById(id), "删除成功", "删除错误");
    }

}
